package com.springboot2.service.Impl;

import com.springboot2.entity.Product;
import com.springboot2.mapper.ProductMapper;
import com.springboot2.service.ProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService {

    @Resource
    private ProductMapper productMapper;

    @Override
    public void add(Product product) {
        productMapper.add(product);
    }

    @Override
    public void del(int id) {
        productMapper.del(id);
    }

    @Override
    public void update(Product product) {
        productMapper.update(product);
    }

    @Override
    public Product findById(int id) {
        return productMapper.findById(id);
    }

    @Override
    public List<Product> findByPage(int pageNo, int pageSize) {
        Map<String,Integer> map = new HashMap<>();
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);
        return productMapper.findByPage(map);
    }

    @Override
    public int count() {
        return productMapper.count();
    }

    @Override
    public List<Product> findByPageParams(int pageNo, int pageSize, String name) {
        Map<String,Object> map = new HashMap<>();
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("name",name+"%");
        return productMapper.findByPageParams(map);
    }

    @Override
    public int countParams() {
        return productMapper.countParams();
    }
}
